package com.goodving.guli.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

import com.goodving.guli.bt.profile.scale.GuliLog;

/* renamed from: cn.com.smartdevices.bracelet.d.a */
public abstract class C0853a extends SQLiteOpenHelper {
    private static final String f4356a = "origin_db";
    private static final int f4357b = 14;
    private static final int f4358c = 14;

    public C0853a(Context context) {
        super(context, f4356a, null, f4358c);
    }

    private void m8947a(SQLiteDatabase sQLiteDatabase) {
        C0840D.m8909b(sQLiteDatabase);
        C0837A.m8906b(sQLiteDatabase);
        C0856c.m8992b(sQLiteDatabase);
        if (sQLiteDatabase.getVersion() <= 11) {
            C0863j.m8997b(sQLiteDatabase);
        }
    }

    private void m8948c() {
        try {
            close();
        } catch (IllegalStateException e) {
            GuliLog.tracePrintError("DB", e.getMessage());
        }
    }

    protected SQLiteDatabase m8949a(boolean z) {
        if (!z) {
            return super.getReadableDatabase();
        }
        try {
            return super.getWritableDatabase();
        } catch (Exception e) {
            GuliLog.tracePrintError("DB", e.getMessage());
            return z ? super.getWritableDatabase() : super.getReadableDatabase();
        }
    }

    protected void m8950a() {
        GuliLog.tracePrintInfo("DB", "dropAllDataTable");
        SQLiteDatabase a = m8949a(true);
        C0840D.m8907a(a);
        C0837A.m8904a(a);
        C0856c.m8990a(a);
        if (a.getVersion() <= 11) {
            C0863j.m8995a(a);
        }
    }

    protected void m8951b() {
        m8948c();
        try {
            m8949a(false);
        } catch (SQLiteException e) {
            GuliLog.tracePrintError("DB", e.getMessage());
        }
    }

    public void onCreate(SQLiteDatabase sQLiteDatabase) {
        GuliLog.tracePrintInfo("DB", "onCreate");
        m8947a(sQLiteDatabase);
    }

    public void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        super.onDowngrade(sQLiteDatabase, i, i2);
        GuliLog.tracePrintInfo("DB", "onDowngrade  oldVersion = " + i + "  newVersion = " + i2);
    }

    public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        GuliLog.tracePrintInfo("DB", "onUpgrade  oldVersion = " + i + "  newVersion = " + i2);
        if (i2 >= 2) {
            m8947a(sQLiteDatabase);
        }
        C0840D.m8908a(sQLiteDatabase, i, i2);
        C0863j.m8996a(sQLiteDatabase, i2, i);
        C0837A.m8905a(sQLiteDatabase, i2, i);
        C0856c.m8991a(sQLiteDatabase, i, i2);
    }
}
